﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace AdventureWorks.Entities
{
	public class ProductCategory : Entity
	{
		[Column("ProductCategoryID")]
		public override int ID { get; set; }

		//public int ParentProductCategoryID { get; set; }

        [Display(Name = "Category Name")]
        [Required]
        [MaxLength(50)]
		public String Name { get; set; }

        [Display(Name = "Modified Date")]
        [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
		public override DateTime ModifiedDate { get; set; }

		public virtual ICollection<Product> Products { get; set; }
		public virtual ICollection<ProductCategory> ProductCategories { get; set; }
		public virtual ProductCategory productCategory { get; set; }

		public override Boolean Validate()
		{

			if (String.IsNullOrEmpty(Name))
				ThrowInvalidEntityException(ExceptionMessages.NameInvalid);

			if (ModifiedDate == DateTime.MinValue)
				ModifiedDate = DateTime.Now;

			return true;
		}

		public override string ToString()
		{
			return Name;
		}
	}
}